<template>
  <div class="app">
    <div v-if="isShowEdit">
      <input type="text" v-model="title" ref="inputRef" />
      <button>确认</button>
    </div>
    <div v-else>
      <span>{{ title }}</span>
      <button @click="edit">编辑</button>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      title: '很划算',
      isShowEdit: false,
      editValue: '',
    }
  },
  methods: {
  async  editFn() {
    // 显示编辑框
    this.isShowEdit = true
    this.isShowEdit=false
    this.isShowEdit=true
    //vue是异步更新完毕，再获取焦点
    await this.$nextTick()
    // 编辑框获取焦点
    this.$refs.inputRef.focus()
    },
  },
}
</script>

<style>
</style>